package entities;

import view.ChessBoard;

import javax.swing.*;
import java.awt.*;

/***
 * Author: Mr.Zhao, Time: 2018/5/9/16:28
 * Description: 一个环，用来标记棋子移动后的位置
 */
public class PieceLoop extends JLabel {
    /* 用来包裹的棋子 */
    private BasePiece piece;
    private Color color;
    /* 环的直径 */
    private int loopDiameter;
    /* 要绘制的线宽 */
    private int lineWidth = 5;

    public PieceLoop(BasePiece piece) {
        ChessBoard chessBoard = ChessBoard.getInstance();
        this.piece = piece;
        this.color = piece.getColor();
        this.loopDiameter = piece.getDiameter();
        this.setBounds(piece.getX() - lineWidth, piece.getY() - lineWidth,
                loopDiameter + lineWidth * 2, loopDiameter + lineWidth * 2);
    }

    @Override
    protected void paintComponent(Graphics g) {
        g.setColor(color);
        Graphics2D g2 = (Graphics2D) g;
        g2.setStroke(new BasicStroke(lineWidth));
        g2.drawOval(lineWidth, lineWidth, loopDiameter, loopDiameter);
    }
}
